#include "head.h"

int system_init(struct all_info *all_storage, struct mutex *mutex, struct cond *cond)
{
	link_data = create_linkqueue();
	link_cmd = create_linkqueue();
	link_db = create_linkqueue();
	bzero(all_storage, sizeof(struct all_info));
	pthread_mutex_init(&mutex->mutex_global, NULL);
	pthread_mutex_init(&mutex->mutex_sqlite, NULL);
	pthread_mutex_init(&mutex->mutex_analysis, NULL);
	pthread_mutex_init(&mutex->mutex_refresh, NULL);
	pthread_mutex_init(&mutex->mutex_zigbee_recv, NULL);
	pthread_mutex_init(&mutex->mutex_zigbee_send, NULL);
	pthread_mutex_init(&mutex->mutex_led, NULL);
	pthread_mutex_init(&mutex->mutex_camera, NULL);
	pthread_mutex_init(&mutex->mutex_buzzer, NULL);
	pthread_mutex_init(&mutex->mutex_link_data, NULL);
	pthread_mutex_init(&mutex->mutex_link_cmd, NULL);
	pthread_mutex_init(&mutex->mutex_link_db, NULL);
	pthread_cond_init(&cond->cond_sqlite, NULL);
	pthread_cond_init(&cond->cond_request, NULL);
	pthread_cond_init(&cond->cond_refresh, NULL);
	pthread_cond_init(&cond->cond_led, NULL);
	pthread_cond_init(&cond->cond_buzzer, NULL);
	pthread_cond_init(&cond->cond_analysis, NULL);
	pthread_cond_init(&cond->cond_zigbee_send, NULL);
	pthread_create(&thread.thread_refresh, NULL, refresh_handler, NULL);
	pthread_create(&thread.thread_sqlite, NULL, sqlite_handler, NULL);
	pthread_create(&thread.thread_analysis, NULL, analysis_handler, NULL);
	pthread_create(&thread.thread_zigbee_recv, NULL, zigbee_recv_handler, NULL);
	pthread_create(&thread.thread_zigbee_send, NULL, zigbee_send_handler, NULL);
	pthread_create(&thread.thread_led, NULL, led_handler, NULL);
	pthread_create(&thread.thread_camera, NULL, camera_handler, NULL);
	pthread_create(&thread.thread_buzzer, NULL, buzzer_handler, NULL);
	pthread_create(&thread.thread_request, NULL, request_handler, NULL);
#if DEBUG_TEST
	pthread_create(&thread.thread_input_test, NULL, input_test_handler, NULL);
	pthread_create(&thread.thread_output_test, NULL, output_test_handler, NULL);
#endif
}
